package com.smmisia.article.controller;

import cn.hutool.core.lang.Assert;
import com.smmisia.article.entity.AttractionBusiness;
import com.smmisia.article.exception.customException;
import com.smmisia.article.mapper.AttractionBusinessMapper;
import com.smmisia.article.service.GroupService;
import com.smmisia.common.Result.Result;
import com.smmisia.common.request.feign.request.FeignCreateGroupRequest;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api")
@RestController
@Tag(name = "api", description = "api")
public class ApiController {

    @Autowired
    private AttractionBusinessMapper attractionBusinessMapper;

    @Autowired
    private GroupService groupService;

    /**
     * 添加景点和商家关联
     * @param attractionId
     * @param businessId
     * @return
     */
    @GetMapping("/insertAttraction")
    public Result<Boolean> insertAttraction(Integer attractionId,Integer businessId){
        AttractionBusiness attractionBusiness = new AttractionBusiness();
        attractionBusiness.setAttractionId(attractionId);
        attractionBusiness.setBusinessId(businessId);
        Assert.notNull(attractionBusinessMapper.insert(attractionBusiness),()->new customException("添加失败"));
        return Result.ok(true);
    }

    /**
     * 加入群组
     * @param accompanyId
     * @return
     */
    @GetMapping("/add")
    public Result<Boolean> addGroup(Integer accompanyId, Integer userId) {
        return groupService.add(accompanyId,userId);
    }

    /**
     * 创建群组
     * @param request
     * @return
     */
    @PostMapping("/create")
    public Result<Boolean> createGroup(@Valid @RequestBody FeignCreateGroupRequest request) {
        return groupService.create(request);
    }

    /**
     * 解散群组
     * @param accompanyId
     * @return
     */
    @GetMapping("/remove")
    public Result<Boolean> removeGroup(@RequestParam Integer accompanyId) {
        return groupService.disband(accompanyId);
    }
}
